package com.hospital.dept.yuan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hospital.dept.yuan.dao.DepartmentMapper;
import com.hospital.dept.yuan.entity.Department;
import com.hospital.dept.yuan.entity.Department_CT;
import com.hospital.dept.yuan.service.CtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class Serviceimpl implements CtService {

    @Autowired
    private DepartmentMapper mapper;

    @Override
    public PageInfo<Department_CT> CtPaging(Integer PageNum, String CuserName, Integer CdiagnoseNO) {
        PageHelper.startPage(PageNum, 6);
        List<Department_CT> departments = mapper.CtPaging(CuserName, CdiagnoseNO);
        return new PageInfo<>(departments);
    }

    //查询未照片
    @Override
    public PageInfo<Department> ctListOne(Integer id,String userName,String userType, Integer pageNum) {
        PageHelper.startPage(pageNum, 4);
        List<Department> dept = mapper.ctListOne(id,userName,userType);
        PageInfo<Department> page = new PageInfo<>(dept);
        return page;
    }

    //查询已照片
    @Override
    public PageInfo<Department> ctListTwo(String userName, Integer pageNum) {
        PageHelper.startPage(pageNum, 5);
        List<Department> dept = mapper.ctListTwo(userName);
        PageInfo<Department> page = new PageInfo<>(dept);
        return page;
    }

    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED)
    public boolean insertCt(Department_CT ct) {
        mapper.insert(ct);
        mapper.update(ct.getCdiagnoseNO(),"");
        return true;
    }

    //新增ct记录
    @Override
    public boolean modify(Integer userid, Integer state) {
        Integer modify = mapper.modify(userid, state);
        if (modify == 1) {
            return true;
        }
        return false;
    }

    @Override
    public boolean addCt(Department_CT ct) {
        Integer integer = mapper.addCt(ct);
        if (integer == 1) {
            return true;
        }
        return false;
    }

    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED)
    public boolean insertCT(Department_CT department_ct,String userTime) {
        int integer = mapper.insertCT(department_ct);
        int update = mapper.update(department_ct.getCdiagnoseNO(),userTime);
        if (integer>0 && update>0) {
            return true;
        }
        return false;
    }

    @Override
    public List<Department_CT> hiszd(Integer cdiagnoseNO) {
        return mapper.hiszd(cdiagnoseNO);
    }
}
